#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2020-11-18 9:23 上午
# @Author  : yangdy
# @File    : 2020-11-18.134.加油站
# @Software: PyCharmCE
from tools.my_methods import *


class Solution:
    def canCompleteCircuit(self, gas: List[int], cost: List[int]) -> int:
        m, mi, v = 0, -1, 0
        for i in range(len(gas)):
            v += gas[i] - cost[i]
            if v < m:
                m, mi = v, i

        return (mi + 1) % len(gas) if v >= 0 else -1


questions = [
    ([1, 2, 3, 4, 5], [3, 4, 5, 1, 2])
]

work(questions, lambda q: Solution().canCompleteCircuit(q[0], q[1]))
